package com.tancire.sources.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.sources.domain.SurResource;
import com.tancire.sources.service.ISurResourceService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 资源管理Controller
 *
 * @author chenchao
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/sources/surResource")
public class SurResourceController extends BaseController {
    @Resource
    private ISurResourceService surResourceService;

    /**
     * 查询资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('sources:surResource:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurResource surResource) {
        startPage();
        List<SurResource> list = surResourceService.selectSurResourceList(surResource);
        return getDataTable(list);
    }

    /**
     * 导出资源管理列表
     */
    @PreAuthorize("@ss.hasPermi('sources:surResource:export')")
    @Log(title = "资源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurResource surResource) {
        List<SurResource> list = surResourceService.selectSurResourceList(surResource);
        ExcelUtil<SurResource> util = new ExcelUtil<SurResource>(SurResource.class);
        util.exportExcel(response, list, "资源管理数据");
    }

    /**
     * 获取资源管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sources:surResource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(surResourceService.selectSurResourceById(id));
    }

    /**
     * 新增资源管理
     */
    @PreAuthorize("@ss.hasPermi('sources:surResource:add')")
    @Log(title = "资源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurResource surResource) {
        return toAjax(surResourceService.insertSurResource(surResource));
    }

    /**
     * 修改资源管理
     */
    @PreAuthorize("@ss.hasPermi('sources:surResource:edit')")
    @Log(title = "资源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurResource surResource) {
        return toAjax(surResourceService.updateSurResource(surResource));
    }

    /**
     * 删除资源管理
     */
    @PreAuthorize("@ss.hasPermi('sources:surResource:remove')")
    @Log(title = "资源管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(surResourceService.deleteSurResourceByIds(ids));
    }
}
